<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-card-header">
                        <!-- <span>所有会员列表</span> -->
                        <a class="layui-btn layui-btn-normal" id="add_article">
                            <i class="layui-icon">&#xe654;</i>
                            <span>新增</span>
                        </a>
                    </div>
                    <div class="layui-card-body">
                        <table id="base_list" lay-filter="test" class="base_list"></table>
                        <script type="text/html" id="barDemo_hash">
                            <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit">修改</a>
                            <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="banner_img">
    <img layer-src="{{d.imgUrl}}" src="{{d.imgUrl}}"/>
</script>

<script>

    layui.config({
        base: '/src/js/'
    }).use(['admin', 'jquery', 'mockjs', 'table', 'sidebar', 'form'], function () {
        var $ = layui.jquery,
            admin = layui.admin,
            layer = layui.layer,
            table = layui.table,
            sidebar = layui.sidebar,
            form = layui.form;

        var base_table;
        //第一个实例
        base_table = table.render({
            method: 'post',
            limit: 10,
            elem: '#base_list',
            height: 'full-235',
        
            url: GET_STUDY_CENTER_LIST, //数据接口
            request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            parseData: function (res) {
				console.log('http:response:' + JSON.stringify(res));
                return {
                    "code": res.status,
                    "msg": res.msg,
                    "count": res.data.count,
                    "data": res.data.list
                };
            },
            page: {
                theme: "#1E9FFF"
            }, //开启分页
            cols: [
                [ //表头
                    {
                        field: 'id',
                        title: 'ID',
                        width: 80,
                        align: 'center',
                        fixed: 'left'
                    }, {
        				field: 'title',
        				title: '标题',
        				align: 'center'
        			}, {
        				field: 'level',
        				title: '等级',
        				align: 'center',
						width: 100,
						templet:function(d){
							switch(d.level){
								case 1:return "L1级";
								case 2:return "L2级";
								case 3:return "L3级";
								case 4:return "L4级";
								case 5:return "L5级";
								case 6:return "L6级";
								case 7:return "L7级";
								case 8:return "L8级";
								case 9:return "L9级";
								case 10:return "L10级";
							}
						}
        			}, {
                        field: 'createDate',
                        title: '创建时间',
                        width: 180,
                        align: 'center',
						templet:function(d){
							return timestampToTime(d.updateDate);
						}
                    },{
        				field: 'state',
						title: '发布状态',
        				align: 'center',
						width: 150,
						templet:function(d){
							if(d.state == 0){
								return "未发布";
							}
							if(d.state == 1){
								return "已发布";
							}
						}
        			}, {
        				fixed: 'right',
        				width: 200,
        				align: 'center',
        				toolbar: '#barDemo_hash'
        			},
        		]
            ]
        });

        table.on('tool(test)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;

            if (layEvent === 'edit') {
                window.location.href = "?id=" + data.id + "#/manager/editStudyCenter";
            } else if (layEvent === 'del') {
                layer.confirm('确定要删除这个学习数据吗？', function (index) {
                    httpPost(DELETE_STUDY_CENTER, {id: data.id}, function (results) {
                        obj.del();
                        layer.close(index);
                    }, function (message) {
                    });
                });
            }
        });


        $("#add_article").on('click', function () {
			window.location.href = "?#/manager/editStudyCenter";
        });

    });


</script>

<style scoped>

</style>
